// miniprogram/pages/report/QueryStock.js
Page({
  data: {
    remark: true,
    disble: false,
    btnname: "确认提交",
    AreaName: '工厂',
    caption: '',
    Temp: true,
    AreaId: '1',
    items: [{ "FullName": "工厂", "typeId": "1" }, { "FullName": "销售", "typeId": "2" }],
  },
  wselect(e) {
    var that = this;
    var Index = e.detail.value;
    console.log(Index);
    this.setData({
      AreaName: that.data.items[Index].FullName,
      AreaId: that.data.items[Index].typeId
    })
  },
  getDate: function () {    
    var that = this;
    wx.cloud.callFunction({
      name: 'GetPost',
      data: {
        data: "fun=5&QueryStr=" + that.data.caption + "&QueryStr1=" + that.data.AreaName
        //data: "fun=5&QueryStr=原料&QueryStr1=工厂"         
      },
      success: res => {
        console.log(res);
        if (res.result != "[]") {
          let obj = JSON.parse(res.result)
          that.setData({  Temp: false,list: obj })
        } else {
          that.setData({  Temp: true})
          wx.showToast({
            icon: 'none',
            title: '没有找到【'+that.data.caption+'】相关数据！',
          })
        }
      },
      fail: err => {
        wx.showToast({
          icon: 'none',
          title: '调用失败',
        })
      }
    })
  },
  submitForm: function (e) {
    let {
      caption
    } = e.detail.value;
    if (!caption) {
      wx.showToast({
        icon: 'none',
        title: '请输入相关信息！',
      });
      return;
    }

    var timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000;
    var qq = timestamp + 15;
    if (qq - wx.getStorageSync('qq') < 0) {
      wx.showToast({
        icon: 'none',
        title: '请稍等15秒后再提交！',
      });
      return false;
    }
    wx.setStorageSync('qq', qq + 15)
    this.setData({caption: caption, remark: false });
    this.getDate();
  },
  showit: function () {
    this.setData({ remark: true });
  }
})